/*
 * com.xy
 */

package com.kly.sc.api.infras.exception;

import com.kly.sc.api.infras.enums.BasicErrorCodeEnum;
import com.fqgj.exception.enums.ErrorCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yujianfu
 * @since 1.0
 */
public class ApplicationException extends RuntimeException {
    /**
     *
     */
    private static final long serialVersionUID = -1965485273396810186L;

    private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationException.class);

    private Integer errorId;

    public ApplicationException(String message) {
        super(message);
        this.errorId = BasicErrorCodeEnum.INTERNAL_SERVER_ERROR.getCode();
    }

    public ApplicationException(Integer code, String message) {
        super(message);
        this.errorId = code;
    }

    public ApplicationException(ErrorCodeEnum enums) {
        super(enums.getMsg());
        this.errorId = enums.getCode();
    }

    public ApplicationException(ErrorCodeEnum enums, String message) {
        super(message);
        this.errorId = enums.getCode();
    }

    public ApplicationException(String message, Throwable cause) {
        super(message, cause);
        this.errorId = BasicErrorCodeEnum.INTERNAL_SERVER_ERROR.getCode();
        LOGGER.error("### error ###::{} and detail {}", message, cause);
    }


    public Integer getErrorId() {
        return errorId;
    }

}
